package com.luom.usercenter.exception;

import com.luom.usercenter.common.BaseResponse;
import com.luom.usercenter.common.ErrorCode;
import com.luom.usercenter.common.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * 全局异常处理器
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public BaseResponse businessExceptionHandler(BusinessException e){
        log.error("businessException"+e.getMessage(),e);
        System.out.println(e.getCode());
        System.out.println(e.getMessage());
        System.out.println(e.getDescription());
        return ResultUtils.error(e.getCode(),e.getMessage(), e.getDescription());
//        return null;
    }

    @ExceptionHandler(RuntimeException.class)
    public BaseResponse businessExceptionHandler(RuntimeException e){
        log.error("runtimeException",e);
        return ResultUtils.error(ErrorCode.SYSTEM_ERROR,e.getMessage(),"");
    }
}
